﻿@model Content
@{ 
    var comments = ViewData["Comments"] as IEnumerable<ContentComment>;//回复
    var hotContents = ViewData["HotContents"] as IEnumerable<Content>;//热门帖子
    var userContents = ViewData["UserContents"] as IEnumerable<Content>;//
    var needPay = (bool)ViewData["NeedPay"];//是否需要支付
    var paidUsers = ViewData["PaidUsers"] as IEnumerable<Tuple<User, UserContentPayHistory>>;//已付费用户
}
<div class="container mt-3 mb-3">
    <div class="row">
        <div class="col-md-8 col-sm-12">

            @if (Model.Status == ContentStatus.Draft)
            {
                <div class="alert alert-warning">
                    <i class="fa fa-info-circle"></i> 当前状态是草稿，仅自己能查看。
                </div>
            }

            <div class="row">
                <div class="col">
                    <div class="border-bottom mb-3 row">
                        <div class="col-md-@(!Model.IsFree()?("9"):"12") col-sm-12">
                            <h3>
                                @if (Model.IsOriginal)
                                {
                                    <span class="badge badge-success">原</span>
                                }
                                @if (Model.IsSecret)
                                {
                                    <span class="badge badge-primary">私</span>
                                }
                                @Model.Subject
                            </h3>
                            <ul class="list-inline text-muted mt-3 text-sm">
                                <li class="list-inline-item">@Model.Category?.Name</li>
                                <li class="list-inline-item"><i class="far fa-calendar-alt"></i> @Model.PostedTime.ToChineseDateTimeString()</li>
                                <li class="list-inline-item"><i class="fas fa-eye"></i> @Model.VisitNum</li>
                                <li class="list-inline-item"><i class="far fa-comments"></i> @comments.Count()</li>
                            </ul>
                        </div>
                        @if (!Model.IsFree())
                        {
                            <div class="col-md-3 d-none d-md-block">

                                <div class="border rounded text-center p-1">
                                    <h4><i class="fa fa-database text-golden"></i> <span class="text-xxl"><b>@Model.Cost</b></span></h4>
                                    <span title="点击看详情" data-toggle="modal" data-target="#paidUserModal" class="pointer hover-underline">已有 @paidUsers.Count() 人交了学费</span>
                                </div>
                            </div>
                        }
                        <div class="col-12">

                            <div class="bdsharebuttonbox">
                                <a href="#" class="bds_more" data-cmd="more"></a>
                                <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
                                <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
                                <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
                                <a href="#" class="bds_youdao" data-cmd="youdao" title="分享到有道云笔记"></a>
                                <a href="#" class="bds_copy" data-cmd="copy" title="分享到复制网址"></a>
                            </div>
                            <script>
                                    window._bd_share_config = {
                                        "common": {
                                            "bdSnsKey": {},
                                            "bdText": "@Html.Raw(Model.Subject)",
                                            "bdMini": "1",
                                            "bdMiniList": false,
                                            "bdPic": "",
                                            "bdDesc": '@Html.Raw(Model.Subject)',
                                            "bdStyle": "0",
                                            "bdSize": "32"
                                        },
                                        "share": {},
                                        "image": {
                                            "viewList": ["weixin", "qzone", "sqq", "tsina", "youdao", "copy"],
                                            "viewText": "分享到：", "viewSize": "16"
                                        }
                                    };
                                    with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
                            </script>
                        </div>
                    </div>
                    @if (needPay)
                    {
                        <div class="alert alert-warning">
                            <h4>
                                <i class="fa fa-info-circle"></i> 当前知识内容需要支付一定的学费才可以阅读
                                @if (User.Identity.IsAuthenticated)
                                {
                                    var myTradingPoints = User.Identity.GetClaimValue<int>
                                        (nameof(DotNetStar.TheKing.Domain.User.TradingPoints));

                                    if (myTradingPoints < Model.Cost)
                                    {
                                        <span>您的金币（@myTradingPoints）不足以进行支付（所需：@Model.Cost）</span>
                                    }
                                    else
                                    {
                                        <button class="btn btn-danger" onclick="payContent()"><i class="fa fa-money-bill-alt"></i> 点这里进行支付</button>
                                    }
                                }
                                else
                                {
                                    <a asp-page="/Account/Login" asp-route-returnUrl="@ViewContext.HttpContext.Request.ToAbsoluteUrl()" class="btn btn-dark"><i class="fa fa-sign-in-alt"></i> 请您先登录</a>
                                }

                            </h4>
                        </div>
                    }
                    else
                    {

                        @Html.Partial("/Pages/Shared/_MarkdownBody.cshtml", new MarkdownBodyViewModel { Id = $"content-{Model.Id}", Body = Model.Body, MinHeight = 300 })
                    }
                   
                        <div class="mt-3 mb-3 mx-auto text-center w-25 p-3 border rounded">
                            <span class=" pointer" id="like" v-on:click="like()" title="点赞">
                                <i class="fa-2x fa-thumbs-up" v-bind:class="likeClass"></i>
                                <span class="text-xxl">{{likeNum}}</span>
                            </span>
                        </div>

                    @if (Model.IsOriginal)
                    {
                        <blockquote class="mt-5 p-3 border rounded text-muted" style="background-color:#eee;font-weight:bold">
                            帖子是本站作者原创，若想转载请注明出处。本文链接： @($"{ViewContext.HttpContext.Request.ToAbsoluteUrl()}")
                        </blockquote>
                    }
                </div>
            </div>

            <!--标签-->
            <div class="border-top mt-3">
                <div class="float-left">
                    <i class="fa fa-tags"></i>
                    @foreach (var item in Model.GetTagNames())
                    {
                        <a asp-page="/Content/Search" asp-route-keyword="@item" target="_blank">
                            <span class="badge badge-info">@item</span>
                        </a>
                    }
                </div>
                <div class="float-right text-sm">
                    @if (User.Identity.IsAuthenticated && User.Identity.UserId() == Model.Author.Id)
                    {
                        <a target="_blank" asp-page="./Edit" asp-route-id="@Model.Id" class=" text-muted"><i class="fa fa-edit"></i> 编辑</a>

                        <a href="javascript:removeContent('@Model.Id');" class=" text-muted"><i class="fa fa-trash"></i> 删除</a>
                    }
                </div>
            </div>

            <!--回复-->
            <div class="row mt-5">
                <div class="col-12">

                    <h4>相关回复(@comments.Count())</h4>
                    <hr>
                    @if (!comments.Any())
                    {
                        <div class="text-center mt-3">暂无任何数据</div>
                    }
                    else
                    {
                        <ul class="list-unstyled">

                            @foreach (var item in comments)
                            {
                                <li class="media mt-3 border-bottom p-2 rounded" id="comment-@item.Id">
                                    <a asp-page="/user/index" asp-route-userId="@item.Author.Id">
                                        <img class="mr-3 rounded img-avatar-100" src="@item.Author.AvatarUrl" alt="@item.Author.UserName">
                                        <p class="text-center">@item.Author.UserName</p>
                                    </a>
                                    <div class="media-body">
                                        @Html.Partial("/Pages/Shared/_MarkdownBody.cshtml", new MarkdownBodyViewModel { Id = $"comment-{item.Id}", Body = item.Body })
                                        <hr />

                                        <div class="row">
                                            <div class="col-12">
                                                <ul class="list-inline text-muted text-sm w-25">
                                                    <li class="list-inline-item"><i class="far fa-clock"></i> @item.PostedTime.ToHumanDateTimeString()</li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            }
                        </ul>
                    }
                </div>
                <div class="col-12 mt-3">
                    @if (User.Identity.IsAuthenticated)
                    {
                        <div class="row" id="comment">
                            <div class="col-12">
                                <div class="input-group ">
                                    <textarea class="form-control " v-bind:style="{height:height}" @@focus="focus()" @@blur="blur()"
                                              v-model="comment" placeholder="回复，大于5个字。支持 Markdown 语法" @@keydown.ctrl.enter="submit()">
</textarea>
                                    <div class="input-group-append">
                                        <button class="btn btn-primary btn-block btn-lg" v-on:click="submit()" v-bind:disabled="comment.length<5">
                                            提 交
                                            <br />
                                            Ctrl + Enter
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    }
                    else
                    {
                        <div class="alert alert-warning">
                            <i class="fa fa-info-circle"></i> 登录后可回复，<a asp-page="/Account/Login" class="btn btn-dark" asp-route-returnUrl="@ViewContext.HttpContext.Request.ToRelativeUrl()"><i class="fas fa-sign-in-alt"></i> 点这里去登录</a>
                        </div>
                    }
                </div>
            </div>

        </div>
        <div class="col-md-4 d-none d-md-block">

            @(await Component.InvokeAsync("UserPanel", new { userId = Model.AuthorId }))

            <div class="mt-3 mb-3 border bg-light">
                <div class="border-bottom m-3"><b>TA 的热度排行</b></div>
                <div class="col">
                    @Html.Partial("_ListUnstyled",userContents)
                </div>
            </div>

            <div class="mt-3 mb-3 border bg-light">
                <div class="border-bottom m-3"><b>阅读排行</b></div>
                <div class="col">
                    @Html.Partial("_ListUnstyled",hotContents)
                </div>
            </div>
        </div>
    </div>
</div>
@if (!Model.IsFree())
{
    <div class="modal fade" id="paidUserModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="paidUserModal">交了学费的用户</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body" style="overflow-y:scroll;max-height:500px">
                    @if (!paidUsers.Any())
                    {
                        <h3 class="text-muted text-center">你可以成为第一个学到知识的人</h3>

                    }
                    <ul class="list-group">

                        @foreach (var item in paidUsers)
                        {
                            <li class="list-group-item">
                                <div class="float-left">
                                    <img src="@item.Item1.AvatarUrl" class="img-avatar-25" /> &nbsp; @item.Item1.UserName 交了 <i class="fa fa-database text-golden"></i> <span class="text-danger">@(item.Item2.Cost)</span> 作为学费
                                </div>
                                <div class="float-right">
                                    <span class="badge badge-primary">@item.Item2.CreatedTime.ToHumanDateTimeString()</span>
                                </div>
                            </li>
                        }
                    </ul>
                </div>
                <div class="modal-footer">
                    共 @(paidUsers.Count()) 人学到了相关知识
                </div>
            </div>
        </div>
    </div>
}
@Html.Hidden("ArticleContent", Html.Raw(Model.Body))